﻿using System;
using System.Collections.ObjectModel;
using Highchart.Core.Data.Chart;
using Highcharts.Core;
using Highcharts.Core.Data.Chart;
using Highcharts.Core.Events;
using Highcharts.Core.PlotOptions;
using Newtonsoft.Json;

namespace DemoWebforms
{
    public partial class Sample09 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            Exemplo09();
        }

        private void Exemplo09()
        {
            //definições de eixos
            hcVendas.YAxis.Add(new YAxisItem { title = new Title("Faturamento") });
            hcVendas.XAxis.Add(new XAxisItem { categories = new[] { "1994", "1995", "1996", "1997", "1998", "1999", "2000", "2001", "2002" } });

            //dados
            var series = new Collection<Serie>();
            series.Add(new DraggableSerie { data = new object[] { 400, 435, 446, 479, 554, 634, 687, 750, 831 }, draggable = true });
            hcVendas.PlotOptions = new PlotOptionsLine { dataLabels = new DataLabels { enabled = true } };
            hcVendas.PlotOptions.cursor = "ns-resize";
            //hcVendas.PlotOptions.point = new PlotPointEvents() { events = new ExtendedPointEvents() { drop = "alert(this.y); event.stopImmediatePropagation();" } };
            hcVendas.Appearance.animation = false;

            hcVendas.PlotOptions.dataLabels = new DataLabels {formatter = "this.y.toFixed(2)"};

            //bind do controle
            hcVendas.DataSource = series;
            hcVendas.DataBind();
        }
    }
}

namespace Highchart.Core.Events
{
    [Serializable]
    [JsonObject(MemberSerialization.OptOut)]
    public class ExtendedPointEvents : PointEvents
    {
        private string _drop;
        public string drop
        {
            get
            {
                if (!string.IsNullOrEmpty(_drop))
                    return string.Format("function(event){{ {0} }}", _drop);
                return null;
            }
            set
            {
                _drop = value;
            }
        }
    }
}

namespace Highchart.Core.Data.Chart
{
    [Serializable]
    [JsonObject(MemberSerialization.OptOut)]
    public class DraggableSerie : Serie
    {
        public bool? draggable;
    }

}